// pages/scoreGoods/index.js
var imageUtil = require('../../utils/util.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    httphost: app.data.httphost,
    httpserver: app.data.httpserver,
    card_type:app.globalData.cardType,
    showStateInfo:"",
    score:"",
    scoreType:"",
  },
  bannerLoad: function (e) {
    var imageSize = imageUtil.imageUtil(e)
    this.setData({
      bannerwidth: imageSize.imageWidth,
      bannerheight: imageSize.imageHeight
    })
  }, 
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;

    that.setData({
      score:options.score,
      scoreType:options.scoreType,
    })

    that.setData({
      card_type:app.globalData.cardType
    })
 
    app.onLaunch();
    var that = this; 
    console.log("------------"+options.scoreType)
    wx.request({
      url: that.data.httpserver + 'app/scoreGoodslist?bannerType='+options.scoreType,
      method: 'post',
      data:{"cardType":that.data.card_type},
      header: wx.getStorageSync('header'),
      success:function(resqust){
        var banner = resqust.data.bannerlist
        //组合轮播图片
        for (var i = 0; i < banner.length;i++){
          var app_url = banner[i].app_url

          var attr_value = '';
          if (typeof (app_url) != 'undefined' && app_url.indexOf('/')!=-1){
              banner[i].app_url = app_url.split('/')[0];
              // var attr_name_value = app_url.split('?')[1].split('=');
              var attr_value = app_url.split('/')[1];
          }
          banner[i].attr_value = attr_value;
        }
        if(resqust.data.goodslist.length==0){

          that.setData({
            showStateInfo:"当前暂无此类可兑换商品",
          })
        }
        that.setData({
          banner: banner,
          goods: resqust.data.goodslist,
          cart_count: resqust.data.cart_count,
        })
      }
    })
  },
  goods_info: function (e) {
    var that = this;
    var goods_id = e.currentTarget.dataset.goods_id;
    console.log('goods_id->'+goods_id);
    wx.navigateTo({
      url: '../scoreGoods/info/info?goods_id=' + goods_id+"&score="+that.data.score+"&scoreType="+that.data.scoreType,
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})